package com.hrt.datasender.datadao.service;

import java.util.ArrayList;
import java.util.List;

import com.hrt.datasender.datacollect.drive.DriveLoader;
import com.hrt.datasender.datacollect.drive.DriveParameterMetadata;
import com.hrt.datasender.datacollect.drive.IDrive;
import com.hrt.datasender.datacollect.model.DriveModel;

/**
 * 驱动类
 * 
 * @author gislin
 *
 */
public final class BcDriverService {

    private static volatile BcDriverService instance;

    private BcDriverService() {

    }

    public static BcDriverService getInstance() {
        if (instance == null) {
            synchronized (BcDriverService.class) {
                if (instance == null) {
                    instance = new BcDriverService();
                }
            }
        }
        return instance;
    }

    /**
     * 获取驱动类
     * 
     * @return
     */
    public List<DriveModel> getExistDrives() {
        List<IDrive> drives = DriveLoader.getInstance().getExistDrives();

        List<DriveModel> models = new ArrayList<>();

        for (IDrive drive : drives) {
            DriveModel model = new DriveModel();
            model.setDriveName(drive.getDriveName());
            model.setId(drive.getDriveId());
            model.setNote(drive.getNote());

            models.add(model);
        }

        return models;
    }

    public List<DriveParameterMetadata> getParameterMetadata(String driveId) {

        List<IDrive> drives = DriveLoader.getInstance().getExistDrives();

        List<DriveParameterMetadata> params = null;

        for (IDrive drive : drives) {
            if (drive.getDriveId().equals(driveId)) {
                params = drive.getParameterMetadata();
                break;
            }
        }

        if (params == null) {
            params = new ArrayList<>();
        }

        return params;
    }
}